package com.ruoyi.employment.service.impl;

import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.employment.domain.TEmploymentTrace;
import com.ruoyi.employment.mapper.TEmploymentTraceMapper;
import com.ruoyi.employment.service.ITEmploymentTraceService;
import com.ruoyi.student.api.ClassService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 就业跟踪Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-12-24
 */
@Service
public class TEmploymentTraceServiceImpl implements ITEmploymentTraceService 
{
    @Autowired
    private TEmploymentTraceMapper tEmploymentTraceMapper;

    @Autowired
    private ClassService classService;

    /**
     * 查询就业跟踪
     * 
     * @param id 就业跟踪主键
     * @return 就业跟踪
     */
    @Override
    public TEmploymentTrace selectTEmploymentTraceById(Long id)
    {
        return tEmploymentTraceMapper.selectTEmploymentTraceById(id);
    }

    /**
     * 查询就业跟踪列表
     * 
     * @param tEmploymentTrace 就业跟踪
     * @return 就业跟踪
     */
    @Override
    public List<TEmploymentTrace> selectTEmploymentTraceList(TEmploymentTrace tEmploymentTrace)
    {
        return tEmploymentTraceMapper.selectTEmploymentTraceList(tEmploymentTrace);
    }

    /**
     * 新增就业跟踪
     * 
     * @param tEmploymentTrace 就业跟踪
     * @return 结果
     */
    @Override
    public int insertTEmploymentTrace(TEmploymentTrace tEmploymentTrace)
    {
        if (tEmploymentTrace.getTeacherName() == null){
            String username = SecurityUtils.getLoginUser().getUsername();
            tEmploymentTrace.setTeacherName(username);
        }

        return tEmploymentTraceMapper.insertTEmploymentTrace(tEmploymentTrace);
    }



    /**
     * 修改就业跟踪
     * 
     * @param tEmploymentTrace 就业跟踪
     * @return 结果
     */
    @Override
    public int updateTEmploymentTrace(TEmploymentTrace tEmploymentTrace)
    {
        return tEmploymentTraceMapper.updateTEmploymentTrace(tEmploymentTrace);

    }

    /**
     * 批量删除就业跟踪
     * 
     * @param ids 需要删除的就业跟踪主键
     * @return 结果
     */
    @Override
    public int deleteTEmploymentTraceByIds(Long[] ids)
    {
        return tEmploymentTraceMapper.deleteTEmploymentTraceByIds(ids);
    }

    /**
     * 删除就业跟踪信息
     * 
     * @param id 就业跟踪主键
     * @return 结果
     */
    @Override
    public int deleteTEmploymentTraceById(Long id)
    {
        return tEmploymentTraceMapper.deleteTEmploymentTraceById(id);
    }

    /**
     * 新增名字
     * @param tEmploymentTrace
     */
    @Override
    public void addBatch(TEmploymentTrace tEmploymentTrace) {
        List<String> studentNames = tEmploymentTrace.getStudentNames();
        studentNames.forEach(studentName -> {
            TEmploymentTrace tEmploymentTrace1 = new TEmploymentTrace();
            BeanUtils.copyProperties(tEmploymentTrace,tEmploymentTrace1);
            tEmploymentTrace1.setStudentName(studentName);
            insertTEmploymentTrace(tEmploymentTrace1);
        });
    }
}
